<?php
class BatalDao {
    public function getBatal($idCuti) {
        $db = Database::getInstance();
        $con = $db->getConnection(1);

        $query = "SELECT * FROM t_batal WHERE idCuti='$idCuti'";
        //print_r($query);
        $result = $con->prepare($query);
        $result->execute();

        if ($result->rowCount() == 1) {
            $data = $result->fetch();
            return $data;
        }

        return false;
    }

    public function getBatalById($id) {
        $db = Database::getInstance();
        $con = $db->getConnection(1);

        $query = "SELECT * FROM t_batal WHERE id='$id'";
        //print_r($query);
        $result = $con->prepare($query);
        $result->execute();

        if ($result->rowCount() == 1) {
            $data = $result->fetch();
            return $data;
        }

        return false;
    }

    public function createBatal(Batal $batal){
        $db= Database::getInstance();
        $con=$db->getConnection(1);

        $tglBatal=date('Y-m-d');

        $query="INSERT INTO t_batal(idCuti,tglAwal,tglAkhir,jmlHariBatal,Alasan,tglBatal,nip_batal) ";
        $query.=" VALUES('$batal->idCuti','$batal->tglAwal','$batal->tglAkhir','$batal->jmlHari','$batal->alasan','$tglBatal','$batal->nip_batal')";

        $result=$con->prepare($query);
        $result->execute();

        if($result->rowCount()==1){
            return true;
        }

        return false;
    }

    public function updateBatal(Batal $batal){
        $db=Database::getInstance();
        $con=$db->getConnection(1);

        $query="UPDATE t_batal SET tglAwal='$batal->tglAwal',tglAkhir='$batal->tglAkhir',alasan='$batal->alasan',jmlHariBatal='$batal->jmlHari' WHERE id='$batal->id'";

        $result=$con->prepare($query);
        $result->execute();

        if($result->rowCount()==1){
            return true;
        }

        return false;
    }
    
}
class Batal {
    var $id;
    var $idCuti;
    var $tglBatal;
    var $tglAwal;
    var $tglAkhir;
    var $alasan;
    var $nip_batal;
    var $jmlHari;
    
    
}

